package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.MesTecPro;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MesMatbom;
import com.ruoyi.system.service.IMesMatbomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 原料bomController
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@RestController
@RequestMapping("/system/matbom")
public class MesMatbomController extends BaseController
{
    @Autowired
    private IMesMatbomService mesMatbomService;

    /**
     * 查询原料bom列表
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesMatbom mesMatbom)
    {
        startPage();
        List<MesMatbom> list = mesMatbomService.selectMesMatbomList(mesMatbom);
        return getDataTable(list);
    }

    /**
     * 导出原料bom列表
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:export')")
    @Log(title = "原料bom", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesMatbom mesMatbom)
    {
        List<MesMatbom> list = mesMatbomService.selectMesMatbomList(mesMatbom);
        ExcelUtil<MesMatbom> util = new ExcelUtil<MesMatbom>(MesMatbom.class);
        util.exportExcel(response, list, "原料bom数据");
    }

    /**
     * 获取原料bom详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mesMatbomService.selectMesMatbomById(id));
    }

    /**
     * 新增原料bom
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:add')")
    @Log(title = "原料bom", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMatbom mesMatbom)
    {

        return toAjax(mesMatbomService.insertMesMatbom(mesMatbom));
    }

    /**
     * 修改原料bom
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:edit')")
    @Log(title = "原料bom", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMatbom mesMatbom)
    {
        return toAjax(mesMatbomService.updateMesMatbom(mesMatbom));
    }

    /**
     * 删除原料bom
     */
    @PreAuthorize("@ss.hasPermi('system:matbom:remove')")
    @Log(title = "原料bom", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mesMatbomService.deleteMesMatbomByIds(ids));
    }


    /*****/
    //查看bom拥有那些原料接口
    @GetMapping("/matIds")
    public AjaxResult selectProId(@RequestParam("bomId") String bomId) {
        List<String> matIds = mesMatbomService.selectMatId(bomId);
        return AjaxResult.success(matIds);
    }

    //修改原料bom接口
    @PutMapping("/mes/edit/MatBom")
    public AjaxResult editMatBom(@RequestBody MesMatbom mesMatbom){
        return toAjax(mesMatbomService.editMatBom(mesMatbom));
    }


}
